package com.wiserun.develop.contract.service;

import com.wiserun.develop.contract.mapper.ContractMapper;
import com.wiserun.develop.contract.model.Contract;
import com.wiserun.develop.contract.model.ContractDTO;
import com.wiserun.develop.custom.model.Custom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ContractService {
    @Autowired
    private ContractMapper contractMapper;

    /**
     * 查询所有的合同
     * @return
     */
    public List<Contract> getContractList(){
        //根据实际需求自行处理业务逻辑
        List<Contract> list = contractMapper.getList();
        return list;
    }

    /**
     * 按条件查询所有合同信息
     * @param contract
     * @return
     */
    public List<Contract> getContractList(ContractDTO contract){
        System.err.println(contract);
        List<Contract> list = contractMapper.getList(contract);
        return  list;
    }

    /**
     * 条件查询统计查询的数量
     * @param contract 条件查询
     * @return 统计数量
     */
    public Integer getNumList(ContractDTO contract){
        return contractMapper.getNumList(contract);
    }

    /**
     *新增合同信息
     * @param contract 合同
     * @return
     */
    public int addContract(Contract contract){
        if(contract != null) {
           return contractMapper.addContract(contract);
        }
        return 0;
    }

    /**
     * 修改合同信息
     * @param contract
     * @return
     */
    public int updateContract(Contract contract){
        if(contract == null || contract.getContid()==0) {
            return 0;
        }
        return contractMapper.updateContract(contract);
    }

    /**
     * 删除合同信息
     * @param contid
     * @return
     */
    public int deleteContract(Integer contid){
        if(contid == null || contid == 0){
            return 0;
        }
        return contractMapper.deleteContract(contid);
    }

    public static void main(String[] args) {
        double touzijine = 22367.22;
        double zhuanrangfene = 10000;
        double touzifene = 20000;
        double yuanqixian = 146;
        double reverate= 0.0488;
        double surplusday = 124;
        double year = 365;
        double mount;

        mount = (touzijine * zhuanrangfene / touzifene) * (1+ yuanqixian*reverate/year) /1 + surplusday*reverate /365;
        double count = (22367.22 * 10000 / 20000) *(1+(146*0.0488/365)) / 1+(124*0.0488/365);
        for(int i =0;i<=124;i++){
            mount = (touzijine * zhuanrangfene / touzifene) * (1+ yuanqixian*reverate/year) /(1 + i*reverate /365);
            //System.out.println("剩余"+i+"天转让金额="+mount);
        }
        System.out.println(mount);
    }
}
